/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.fjut.se16;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author danny
 */
public class MyFirstSpring {
    public static void main(String[] args) {
        MyFirstSpring myFirstSpring = new MyFirstSpring();
//        myFirstSpring.classical();
        myFirstSpring.springMethod();
    }
    
    private void classical() {
        HelloSpring helloSpring = new HelloSpring();
        helloSpring.setName("Spring");
        helloSpring.sayHello();
    }
    
    protected void springMethod() {
        // 获取应用上下文
        ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        // 从ctx中获取bean
        HelloSpring bean = (HelloSpring) ctx.getBean("helloSpring");
        // 直接调用bean的方法，直接使用，不用担心nullpointer
        bean.sayHello();
    }
    
}
